package com.atguigu.elasticsearch;

import org.apache.http.HttpHost;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;

import java.io.IOException;

public class ESIndexDelete {

    public static void main(String[] args) throws IOException {

        RestHighLevelClient esClient =
                new RestHighLevelClient(
                        RestClient.builder(
                                new HttpHost("localhost", 9200, "http")
                        ));

        // 查询索引
        DeleteIndexRequest request = new DeleteIndexRequest("user");
        AcknowledgedResponse response = null;
        try {
            response = esClient.indices().delete(request, RequestOptions.DEFAULT);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (null != esClient) {
                esClient.close();
            }
        }

        // 响应状态
        System.out.println(response.isAcknowledged());

    }
}
